window.onload = function() {
    const username = document.getElementById('username');
    const password = document.getElementById('password');
    const btn = document.querySelector('button');

    // 监听输入
    username.addEventListener("input", (e) => {
        console.log("输入:", e.target.value);
    });

    // 登录事件
    btn.addEventListener("click", (e) => {
        e.preventDefault();

        let name = username.value;
        let passd = password.value;

        if (!name || !passd) return;

        // 使用 Fetch（推荐）
        fetch('http://172.19.11.61:8080/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    username: name,
                    password: passd
                })
            })
            .then(response => response.json())
            .then(data => {
                console.log("登录成功", data);
            })
            .catch(error => {
                console.log("登录失败", error);
            });
    });
};
let promise = new Promise((resolve, reject) => {
    // let success=true
    // if(success){
    //     resolve()
    // }else{
    //     reject()
    // }
    setTimeout(() => {
        console.log("五秒到了")
        resolve("今天天气不热")
    }, 5000)
})
promise.then((res) => {
    console.log("成功")
    console.log(res)
}).catch((err) => {
    conslole.log("失败了")
}).finally(() => {
    console.log("无论成功失败                                                                                                                                                             ")
})